package chabernac.android.wordbattle.paint;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import android.graphics.Canvas;
import android.view.View;

public class DrawableComposite extends iDrawable {
  private final List<iDrawable> myDrawables = new ArrayList<iDrawable>();
  
  public void addDrawable(iDrawable aDrawable){
    myDrawables.add(aDrawable);
  }

  @Override
  public void paint(Canvas aCanvas, View aView) {
    Collections.sort(myDrawables, new LayerComparator());
//    Log.d("DrawableComposite", "Start painting composite");
//    long t11 = System.currentTimeMillis();
    for(iDrawable theDrawable: myDrawables){
//      long t1 = System.currentTimeMillis();
      theDrawable.paint(aCanvas, aView);
//      long t2 = System.currentTimeMillis();
//      long delta = t2 - t1;
//      if(delta > 50){
//        Log.d("DrawableComposite", "Painting '" + theDrawable.getClass().getName() + " took " + delta +  " ms");
//      }
    }
//    long t12 = System.currentTimeMillis();
//    Log.d("DrawableComposite", "Painting compostie took '" + (t12 - t11) + "' ms");
  }
}
